package com.lishu.carsafe.widget;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;

import com.lishu.carsafe.R;

public class DialogUtil {

    public interface OnDeleteButtonClickListener{
        void onDeleteButtonClick();
    }

    public interface OnOkButtonClickListener{
        void onOkButtonClick();
    }

    public static void showDeleteDialog(Context context, final OnDeleteButtonClickListener deleteClickListener) {
        final AlertDialog clearCacheDialog = new AlertDialog.Builder(context).create();
        clearCacheDialog.show();
        Window window = clearCacheDialog.getWindow();
        window.setContentView(R.layout.show_delete_dialog);
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        window.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clearCacheDialog.dismiss();
            }
        });
        window.findViewById(R.id.btn_ok).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                deleteClickListener.onDeleteButtonClick();
                clearCacheDialog.dismiss();
            }
        });
    }

    public static void showLogoutDialog(Context context, final OnOkButtonClickListener okClickListener) {
        final AlertDialog clearCacheDialog = new AlertDialog.Builder(context).create();
        clearCacheDialog.show();
        Window window = clearCacheDialog.getWindow();
        window.setContentView(R.layout.show_logout_dialog);
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        window.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clearCacheDialog.dismiss();
            }
        });
        window.findViewById(R.id.btn_ok).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                okClickListener.onOkButtonClick();
                clearCacheDialog.dismiss();
            }
        });
    }
}
